#include <iostream>
#include <utility>
#include <vector>
#include <stack>
using namespace std;
int n, c;
int t;
int Time = 0;
vector<pair<int, int>> a;
vector<bool> visit(1000);
stack<pair<int, int>> stl;
stack<pair<int, int>> str;
int ret = 0;
int Min = 0x3f3f3f3f;
void dfs() {
    if(stl.empty() && str.empty()) {
        Min = min(ret, Min);
    }
    for(int i = 0; i < 2; i++) {
        if(i == 0 && !stl.empty()) {
            auto temp = stl.top();
            stl.pop();
            int tempt = t;
            Time += abs(temp.first - t);
            ret += Time * temp.second;
            t = temp.first;
            dfs();
            stl.push(temp);
            ret -= Time * temp.second;
            t = tempt;
            Time -= abs(temp.first - t); 
        }else if(i == 1 && !str.empty()){
            auto temp = str.top();
            str.pop();
            int tempt = t;
            Time += abs(temp.first - t);
            ret += Time * temp.second;
            t = temp.first;
            dfs();
            str.push(temp);
            ret -= Time * temp.second;
            t = tempt;
            Time -= abs(temp.first - t);  
        }
    } 
    
}
int main() {
    cin >> n >> c;
    for(int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        if(i < c - 1) {
            stl.push(make_pair(x, y));
        }else if(i == c - 1){
            t = x;
        }else {
            str.push(make_pair(x, y));
        }
    }
    stack<pair<int, int>> tempst; 
    while(!str.empty()) {
        tempst.push(str.top());
        str.pop();
    }
    str = tempst;
    dfs();
    cout << Min << endl;
    return 0;
}